﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]//挂脚本的时候自动挂上刚体组件
public class D06_RigidBody1 : MonoBehaviour
{
    private Rigidbody rig;
    private void Start()
    {
        rig = GetComponent<Rigidbody>();
    }

    //当碰撞进入
    //collision 是碰撞信息,包含:对方的碰撞器,碰撞的点,法线
    private void OnCollisionEnter(Collision collision)
    {
        print(collision.collider);//对方的碰撞器,通过这个可以拿到对方的任何组件和父子物体
        print(collision.contacts[0].point);//碰撞点
        print(collision.contacts[0].normal);//碰撞点的法线
        //碰到的物体变红
        collision.collider.GetComponent<MeshRenderer>().material.color = Color.red;
    }
    //当碰撞停留
    private void OnCollisionStay(Collision collision)
    {
        print("OnCollisionStay");
    }
    ////当碰撞退出
    private void OnCollisionExit(Collision collision)
    {
        print("OnCollisionExit");
    }

    private void FixedUpdate()
    {
        rig.WakeUp();
    }
}